# list(), tuple(), set(), dict()
print(list("hello"))  # ['h', 'e', 'l', 'l', 'o']
print(tuple([1, 2, 3]))  # (1, 2, 3)
print(set([1, 2, 2, 3]))  # {1, 2, 3} (自动去重)

# dict() 转换
pairs = [("a", 1), ("b", 2)]
print(dict(pairs))  # {'a': 1, 'b': 2}


# sum() - 求和
scores = [80, 90, 75]
print(sum(scores))  # 245
print(sum([1, 2, 3], 10))  # 16 (可指定初始值)


# sorted() - 返回排序后的新列表
letters = ["b", "d", "a", "c"]
print(sorted(letters))  # ['a', 'b', 'c', 'd']
print(sorted(letters, reverse=True))  # ['d', 'c', 'b', 'a']

# reversed() - 生成反向迭代器
nums = [10, 1, 2, 3, 8, 0]
for n in reversed(nums):
    print(n, end=" ")  # 输出: 3 2 1
print(list(reversed(nums)))  # [3, 2, 1]

sorted_nums = sorted(nums, reverse=True)
print(sorted_nums)

# 枚举和数组，元祖，字典 打包遍历

names = ["linda", "susan"]
ages = (10, 20)
scores = {
    "chinese": 100,
    "math": 90,
}

for name, age, score in zip(names, ages, scores.values()):
    print("name=", name, "age=", age, "score=", score)


# any 和 all函数的使用

value_collection = [1, 2, 0]

any_value_is_true = any(value_collection)
print(any_value_is_true)

all_value_is_true = all(value_collection)

print("all_value_is_true=", all_value_is_true)


# 序列解包
pairs = [("a", 1), ("b", 2), ("c", 3)]

letters, numbers = zip(*pairs)
print(letters)  # ('a', 'b', 'c')
print(numbers)  # (1, 2, 3)

# map 和 filter函数的使用

stus = [{"name": "jackie", "age": 19}, {"name": "susan", "age": 20}]

print(list(map(lambda item: item.name == "linda", stus)))
